package com.androidhuman.example.ListViewExample;

import java.util.ArrayList;
import android.app.ListActivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class ListViewExampleActivity extends ListActivity {
	private ArrayList<String> list;
	private ArrayAdapter<String> adapter;
	private EditText inputText;
	private Button inputButton;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        inputText = (EditText)findViewById(R.id.editText);
        inputButton = (Button)findViewById(R.id.button);
        list = new ArrayList<String>();
        
        inputButton.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				list.add(inputText.getText().toString());
				inputText.setText("");
				adapter.notifyDataSetChanged();
			}
		});
        
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
        setListAdapter(adapter);
        
    }
	    @Override
	    protected void onListItemClick (ListView l, View v, int position, long id){
	    	super.onListItemClick(l, v, position, id);
	    	Toast.makeText(this, list.get(position), Toast.LENGTH_SHORT).show();    
	    }
}	    